package com.example.mobile2021606144ywr0407homework;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity9 extends AppCompatActivity {

    private TextView tvMainTitle8;
    private TextView tvMain81;
    private TextView tvMain82;
    private TextView tvMain83;
    private EditText editMain81;
    private Button btnMain8End;
    private TextView txt8;
    double num=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main9);
        initView();
        btnMain8End.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String a = editMain81.getText().toString();
                if (a.length() == 0) {
                    Toast.makeText(MainActivity9.this, "请输入金额", Toast.LENGTH_SHORT).show();
                } else {
                    double b = Double.parseDouble(a);
                    if (b <= 100000) {
                        num = (b * 0.1);
                        txt8.setText(String.valueOf(num));
                    }
                    if (100000 < b & b < 200000) {
                        num = 100000 * 0.1 + (b - 100000) * 0.075;
                        txt8.setText(String.valueOf(num));
                    }
                    if (2000000 < b & b < 400000) {
                        num = 100000 * 0.1 + 100000 * 0.075 + (b - 200000) * 0.005;
                        txt8.setText(String.valueOf(num));
                    }
                    if (400000 < b & b < 1000000) {
                        num = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.005 + (b - 400000) * 0.015;
                        txt8.setText(String.valueOf(String.valueOf(num)));
                    }
                    if (b > 1000000) {
                        num = 100000 * 0.1 + 100000 * 0.075 + 200000 * 0.005 + 600000 * 0.015 + (b - 1000000);
                        txt8.setText(String.valueOf(num));
                    }
                }
            }
        });
    }

    private void initView() {
        tvMainTitle8 = (TextView) findViewById(R.id.tv_main_title8);
        tvMain81 = (TextView) findViewById(R.id.tv_main8_1);
        tvMain82 = (TextView) findViewById(R.id.tv_main8_2);
        tvMain83 = (TextView) findViewById(R.id.tv_main8_3);
        editMain81 = (EditText) findViewById(R.id.edit_main8_1);
        btnMain8End = (Button) findViewById(R.id.btn_main8_end);
        txt8 = (TextView) findViewById(R.id.txt8);
    }
}